package com.qk.service.impl;

import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.ReportService;
import com.qk.vo.OverviewVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
    @Override
    public OverviewVo overview() {
        Object overviewData = redisTemplate.opsForValue().get("OVERVIEW_DATA");

        if(overviewData != null){
            return (OverviewVo) overviewData;
        }

        //调用线索mapper
        OverviewVo overviewClueVo = clueMapper.overviewClueVo();
        //调用商机mapper
        OverviewVo overviewBusinessVo = businessMapper.overviewBusinessVo();
        //将商机数据复制给线索数据
        BeanUtils.copyProperties(overviewClueVo,overviewBusinessVo,"businessTotal","businessWaitAllot","businessWaitFollow", "businessFollowing", "businessFalse", "businessConvertCustomer");

        redisTemplate.opsForValue().set("OVERVIEW_DATA",overviewBusinessVo, 30, TimeUnit.SECONDS);

        //返回商机数据
        return overviewBusinessVo;
    }
}
